package cn.soft863.servlet.head;

import java.io.IOException;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.websocket.Session;

import cn.soft863.common.servlet.BaseServlet;
import cn.soft863.users.pojo.AUsers;
import cn.soft863.users.service.IUsersService;
import cn.soft863.users.service.impl.UsersServiceImpl;

/**
 * 管理员登陆成功后的操作
 * @author 902-B-Book
 *
 */
public class UsersBackServlet extends BaseServlet
{
	private IUsersService usersService = new UsersServiceImpl();
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		System.out.println("----service------");
		/* 专门接收一个method,*/
		String method = request.getParameter("method");
		if("usersInsert".equalsIgnoreCase(method))
		{
			/* 登陆后的首页 */
			this.usersInsert(request,response);
		}/*else if("usersInsertSubmit".equalsIgnoreCase(method)) {
			this.usersInsertSubmit(request,response);
		}*/
	}
/*
	private void usersInsertSubmit(HttpServletRequest request, HttpServletResponse response)
	{
		System.out.println("======usersInsertSubmit=======");
		
		 如何接收页面的信息呢? 
		 接收参数 
		String balanceId = request.getParameter("balanceId");
		String ordersId = request.getParameter("ordersId");
		String accountId = request.getParameter("accountId");
		String thirdSn = request.getParameter("thirdSn");
		String usersTime = request.getParameter("usersTime");
		String price = request.getParameter("price");
		String bhType = request.getParameter("bhType");
		String status = request.getParameter("status");
		
		 处理参数 
		int balanceIdInt =	Integer.parseInt(balanceId) ;
		int ordersIdInt = Integer.parseInt(ordersId) ;
		int accountIdInt = Integer.parseInt(accountId) ;	
		int usersTimeInt = Integer.parseInt(usersTime) ;
		double priceDouble = Double.parseDouble(price);
		byte bhTypeByte = Byte.valueOf(bhType);
		byte statusByte = Byte.valueOf(status);
		
		 将Test类里面的代码拷贝到此处
		 * 
		 * 为users赋值的时候一切的一切填写的全部是写死的值????
		 * 如何将页面上填写的信息赋值给users对象呢? 
		 *  
		 new对象 
		AUsers users = new AUsers() ; 
		 赋值 	
		 页面上不需要赋值的,后台直接填写 

		users.setBalanceId(balanceIdInt);
		users.setOrdersId(ordersIdInt);
		users.setAccountId(accountIdInt);
		users.setThirdSn(thirdSn);
		users.setConsumeTime(usersTimeInt);
		users.setPrice(priceDouble);
		users.setBhType(bhTypeByte);
		users.setStatus(statusByte);
		users.setCreateTime(new Date());
		users.setUpdateTime(new Date());
		users.setPubTime(new Date());

		
		 调用Service的方法,存储结果
		 * Test类,真的就可以将数据存储到数据库了
		 *  
		int res = this.usersService.saveOneUsersService(users);
		System.out.println(res + "------------------");
		 存储结果 
		if(res > 0 )
		{
			 Sucess 
			this.info = "成功,id:" + users.getId() ; 
		}else
		{
			this.info = "失败" ;
		}
		request.setAttribute("info", info);
		 服务器端跳转到管理员添加的jsp上面 
		url = "/WEB-INF/jsp/back/usersInsert.jsp" ; 
		request.getRequestDispatcher(url).forward(request, response);
		
	}*/

	private void usersInsert(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{

		System.out.println("=====adminsLogin=======");
		/* 服务器端跳转到页面 */
		url = "/WEB-INF/jsp/head/usersRegist.jsp";
		request.getRequestDispatcher(url).forward(request, response);
	}

	
}
